#include <am.h>
#include <klib.h>
#include <klib-macros.h>

#define IP_BASE_ADDR 0x10004000
#define REG_CTRL *((volatile uint32_t *)(IP_BASE_ADDR + 0))
#define REG_PSCR *((volatile uint32_t *)(IP_BASE_ADDR + 4))
#define REG_CNT  *((volatile uint32_t *)(IP_BASE_ADDR + 8))
#define REG_CMP  *((volatile uint32_t *)(IP_BASE_ADDR + 12))
#define REG_STAT *((volatile uint32_t *)(IP_BASE_ADDR + 16))

int main(){
    putstr("timer test\n");

    REG_CTRL = (uint32_t) 0x0;
    while(REG_STAT == 1); // clear irq
    REG_PSCR = (uint32_t) 0x4;
    REG_CMP = (uint32_t) -0xF;
    REG_CTRL = (uint32_t) 0x5;

    for(int i = 0; i < 10; ++i) {
        while(REG_STAT == 0);
        printf("%d timer overflow\n", i);
    }
    return 0;
}
